
#region Imports

using System;

using Justa.Instrumentation;

#endregion

namespace Justa.Service
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    /// <author>Abel Perez (java.aperez@gmail.com)</author>
    /// 
    public sealed class ServiceExceptionHandler
    {
        /// <summary>
        /// 
        /// </summary>
        /// 
        private ServiceExceptionHandler()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="exception"></param>
        /// <param name="message"></param>
        /// <param name="parameters"></param>
        /// 
        public static void Process(Exception exception, string message, params object[] parameters)
        {
            ServiceInstrumentation.FireErrorEvent(message, parameters);
            if (exception == null)
            {
                throw new ServiceException(string.Format(message, parameters));
            }
            throw new ServiceException(string.Format(message, parameters), exception);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="exception"></param>
        /// <param name="supress"></param>
        /// <param name="message"></param>
        /// <param name="parameters"></param>
        /// 
        public static void Process(Exception exception, bool supress, string message, params object[] parameters)
        {
            if (supress == true)
            {
                ServiceInstrumentation.FireWarningEvent(message, parameters);
                return;
            }

            Process(exception, string.Format(message, parameters));
        }
    }
}